package com.chagee.store.operation.server.controller;

import com.alibaba.fastjson.JSON;
import com.chagee.base.utils.HttpResponse;
import com.chagee.base.utils.HttpResponseUtil;
import com.chagee.store.operation.api.request.StorePersonnelRequest;
import com.chagee.store.operation.api.response.StorePersonnelResponse;
import com.chagee.store.operation.common.exception.BizErrorCode;
import com.chagee.store.operation.common.utils.CommonUtil;
import com.chagee.store.operation.server.facade.StorePersonnelFacade;
import com.chagee.store.operation.server.feign.vo.User;
import com.chagee.store.operation.server.feign.vo.UserPostVO;
import com.chagee.store.operation.server.model.param.QueryPersonnelRequest;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springblade.core.secure.utils.AuthUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 人员
 * @Author : hk
 * @Date : 2025/3/7
 */

@Slf4j
@RestController
@RequestMapping("/storePerson")
public class StorePersonnelController {

	@Resource
	private StorePersonnelFacade storePersonnelFacade;


	@PostMapping("/userList")
	@ApiOperation("门店组织人员信息")
	public HttpResponse<List<StorePersonnelResponse>> userList(@RequestBody @Valid StorePersonnelRequest request) {
		log.info("StoreAppSweepController_queryOrderTaskList_request:{}, auth:{}", JSON.toJSONString(request), JSON.toJSONString(AuthUtil.getUser()));
		if (StringUtils.isNotBlank(CommonUtil.validate(request.getStoreNo()))) {
			return HttpResponseUtil.build(null, BizErrorCode.REQUEST_VALID_FAILED.getErrorCode(), CommonUtil.validate(request.getStoreNo()));
		}
		List<StorePersonnelResponse> list = storePersonnelFacade.userList(request);
		return HttpResponseUtil.success(list);
	}

	@PostMapping("/queryPersonnel")
	@ApiOperation("手机号查询人员")
	public HttpResponse<User> userInfoByPhone(@RequestBody @Valid QueryPersonnelRequest request) {
		log.info("StoreAppSweepController_listByPhoneOrCode_request:{}, auth:{}", JSON.toJSONString(request), JSON.toJSONString(AuthUtil.getUser()));
		User userVO = storePersonnelFacade.userInfoByPhone(request);
		return HttpResponseUtil.success(userVO);
	}


}
